<template>
 <section v-loading="loading" class="batch-data">
    <h2>获取批量数据：
      <br>1、【现货市场】-【现货交易】-【日前交易结果】-【一次日前节点电价查询】全网所有节点日前出清节点电价；
      <br>2、【现货市场】-【现货交易】-【实时交易结果】-【实时节点电价查询】全网所有节点实时出清节点电价-正式。
    </h2>
    <el-form
    ref="replaceFormRef"
    :model="replaceForm"
    :rules="replaceRules"
    label-width="auto"
    :inline="true"
  >
    <el-form-item
      label="ID替换JSON数据项："
      prop="nodeIds"
    >
      <el-input
        v-model="replaceForm.nodeIds"
        :autosize="{ minRows: 2, maxRows: 3 }"
        type="textarea"
        placeholder="请输入"
      />
    </el-form-item>
    <el-form-item>
      <el-button  @click="replaceReset">重置</el-button>
      <el-button  @click="replaceCancel">取消</el-button>
      <el-button type="primary" @click="replaceSave">保存</el-button>
    </el-form-item>
    </el-form>
    <el-form
    ref="ruleFormRef"
    :model="ruleForm"
    :rules="rules"
    label-width="auto"
    :inline="true"
  >
    <el-form-item label="数据日期：" prop="certainDate">
      <el-date-picker
        v-model="ruleForm.certainDate"
        type="daterange"
        clearable
        :editable="false"
        placeholder="请选择数据日期"
        format="YYYY-MM-DD"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="YYYY-MM-DD"
        :disabled-date="disabledDate"
        @calendar-change="calendarChange"
      />
    </el-form-item>
    <el-form-item label="数据类型：" prop="reqTypeList">
      <el-select
        v-model="ruleForm.reqType" 
        placeholder="请选择数据类型"
      >
        <el-option 
          v-for="item in dataTypeList" 
          :key="item.value"
          :label="item.label" 
          :value="item.value" 
        />
      </el-select>
    </el-form-item>
    <el-form-item label="验证码：" prop="uniqueCode">
      <el-input v-model.trim="ruleForm.uniqueCode" type="password" placeholder="请输入验证码" />
    </el-form-item>
    <el-form-item>
      <el-button @click="resetForm">重置</el-button>
      <el-button type="primary" @click="submitForm(false)">获取所有节点（自动替换）</el-button>
      <el-button type="primary" @click="submitForm(true)">只获取替换节点</el-button>
    </el-form-item>
  </el-form>
  <div class="req-history">
    <h5>获取记录(不一定成功)::</h5>
    <div class="req-history__item" v-for="item in reqHistory" :key="item.certainDate + Math.random()">
      <div>数据日期：<span>{{ item.certainDate }}</span></div>
      <div>数据类型：<span>{{ item.reqTypes }}</span></div>
    </div>
  </div>
  </section>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { dataTypeList } from './generate'
import {useBatchData} from '.'

const ruleFormRef = ref(null)
const replaceFormRef = ref(null)

const {
    init,
    loading,

    replaceForm,
    replaceRules,
    replaceSave,
    replaceCancel,
    replaceReset,

    ruleForm,
    rules,
    submitForm,
    resetForm,
    reqHistory,
    disabledDate,
    calendarChange
  } = useBatchData(ruleFormRef, replaceFormRef)

  onMounted(init)

</script>

<style lang="scss" scoped>
.batch-data {
  margin-top: 30px;

  :deep(.el-form) {
    .el-select {
      width: initial;
      min-width:200px;
    }
  }
  .req-history {
    margin-top: 30px;
    &__item {
      margin-bottom: 22px
    }
  }
}
</style>